package com.ccqlk.lightpointrelation.runner;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.sql.Connection;

@Slf4j
@Component
public class DataSourcePrewarRunner implements ApplicationRunner {
    @Resource
    private DataSource dataSource;

    @Override
    public void run(ApplicationArguments args) {
        // 触发连接池初始化
        try (Connection conn = dataSource.getConnection()) {
            // 成功触发池子初始化
            log.info("数据库连接池已初始化");
        } catch (Exception e) {
            log.error("初始化数据库连接池失败.",e);
        }
    }
}
